﻿Imports System.Xml
Imports System.Text
Imports Idml.Stories

Public Class StoryLoader

	Function LoadStories(StoryFiles As String()) As List(Of Story)
		Dim Result As New List(Of Story)

		For Each file As String In StoryFiles
			'Debug.WriteLine("Loading story: " & file)
			Result.Add(LoadStory(file))
		Next

		Return Result
	End Function

	Private Function LoadStory(file As String) As Story
		Dim textreader As New IO.StreamReader(file)
		Dim reader As XmlReader
		Dim result As Story

		reader = XmlReader.Create(textreader, New XmlReaderSettings() With {
		  .CloseInput = True,
		  .ConformanceLevel = ConformanceLevel.Document,
		  .DtdProcessing = DtdProcessing.Ignore,
		  .IgnoreComments = True,
		  .IgnoreProcessingInstructions = False,
		  .IgnoreWhitespace = True,
		  .ValidationType = ValidationType.None})

		reader.ReadStartElement("idPkg:Story")

		result = Story.ReadXml(reader)

		reader.Close()

		Return result
	End Function


End Class
